/**
 * test if a path is an external path (starts with http(s)://, mailto: or tel:)
 *
 * @param path: the path to test
 * @returns: wheather it's an external path
 */
export const isExternal = (path: string): boolean => {
  return /^(https?:\/\/|mailto:|tel:)/.test(path);
};

/**
 * test if an url is http or https
 *
 * @param url: the url to test
 * @returns: true if url is http or https, false otherwise
 */
export const isHttp = (url: string): boolean => {
  return url.indexOf("http://") !== -1 || url.indexOf("https://") !== -1;
};

export const isNotEmpty3 = (value: any): boolean => {
  return value !== null && value !== "" && typeof value !== "undefined";
};
// 用于表单验证是否为邮箱格式
export const customEmailRule = (rule, value) => {
  const emailReg = /^([a-zA-Z0-9._%-])+@([a-zA-Z0-9.-])+\.([a-zA-Z]{2,4})$/;
  if (!emailReg.test(value)) {
    return Promise.reject("请输入有效的邮箱地址！");
  }
  return Promise.resolve();
};
// 表单校验密码长度必须大于6小于18
export const customPasswordRule = (rule, value) => {
  if (value.length < 4) {
    return Promise.reject("密码长度必须至少为4个字符！");
  } else if (value.length > 18) {
    return Promise.reject("密码长度不能大于18个字符！");
  }
  return Promise.resolve();
};
